<%--
  Created by IntelliJ IDEA.
  User: CR
  Date: 2019/10/30
  Time: 15:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>Input Page</title>
</head>
<body>
    <form:form action="${pageContext.request.contextPath}/emp" method="POST" modelAttribute="employee">
        <c:if test="${employee.id == null}">
            <%-- path 属性对应 input.name 属性值 --%>
            <p>LastName: <form:input path="lastName" /></p>
        </c:if>
        <c:if test="${employee.id != null}">
            <form:hidden path="id"></form:hidden>
            <input type="hidden" name="_method" value="PUT">
        </c:if>
        <p>Email: <form:input path="email" /></p>
        <%
          Map<String, String> genders = new HashMap();
          genders.put("1", "male");
          genders.put("0", "feMale");
          request.setAttribute("genders", genders);
        %>
        <p>Gender: <form:radiobuttons path="gender" items="${genders}" /></p>
        <p>Departments: <form:select path="department.id"
                                     items="${departments}"
                                     itemLabel="departmentName"
                                     itemValue="id" />
        </p>
        <p><input type="submit" value="submit"></p>
    </form:form>
    <br />
    <a href="emps">List All Employees</a>
</body>
</html>
